package com.dcbeida.adapter;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.dcbeida.R;
import com.dcbeida.activity.salsesdedail.SalsesDetailActivity;
import com.dcbeida.activity.stockdetail.RkStockDetailActivity;
import com.dcbeida.activity.zyff.ZyWithGaDetailActivity;
import com.dcbeida.widget.PhotoViewShow;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by 150410 on 2017/10/19.
 */

public class SalsesDetailRYAdapter extends RecyclerView.Adapter<SalsesDetailRYAdapter.ViewHolder> {
    private Activity activity;

    public ArrayList<String> mUris;

    public SalsesDetailRYAdapter(Activity activity) {
        this.activity = activity;
        mUris = new ArrayList<String>();
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = View.inflate(activity, R.layout.salses_detail_img_item, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        String imgurl=mUris.get(position).toString().replaceAll("\\\\", "");
        Glide.with(activity).load(imgurl).centerCrop().override(150,150).into(holder.imgFp);
        holder.setPosition(position);
    }


    @Override
    public int getItemCount() {
        return null == mUris ? 0 : mUris.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.img_fp)
        ImageView imgFp;
        private int position;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //传递当前点击的图片的位置、图片路径集合
                    Bundle bundle = new Bundle();
                    bundle.putInt("position", position);
                    bundle.putStringArrayList("mImages", mUris);
                    if (activity instanceof SalsesDetailActivity){

                        ((SalsesDetailActivity)activity).showActivity(PhotoViewShow.class,bundle);
                    }else if (activity instanceof RkStockDetailActivity){

                        ((RkStockDetailActivity)activity).showActivity(PhotoViewShow.class,bundle);
                    }else if (activity instanceof ZyWithGaDetailActivity){
                        ((RkStockDetailActivity)activity).showActivity(PhotoViewShow.class,bundle);
                    }
                }
            });
        }

        public void setPosition(int position) {
            this.position = position;
        }
    }

    public void setData(ArrayList<String> paths) {
        mUris = paths;
        notifyDataSetChanged();
    }
}
